Skip to content

gh-122450: Fix docs to state denominator positivity of Fraction#122464

Closed
privet-kitty wants to merge 12 commits into
python:mainfrom
privet-kitty:feature/denominator-positivity
Closed

gh-122450: Fix docs to state denominator positivity of Fraction#122464
privet-kitty wants to merge 12 commits into
python:mainfrom
privet-kitty:feature/denominator-positivity

Conversation

@privet-kitty

@privet-kitty privet-kitty commented Jul 30, 2024

Copy link
Copy Markdown

@ghost

ghost commented Jul 30, 2024

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some redundancy, as docs already says: "The Fraction class inherits from the abstract base class numbers.Rational, and implements all of the methods and operations from that class." and "The numerator and denominator values should be instances of Integral and should be in lowest terms with denominator positive." But I think it's ok.

On another hand, it seems that docstrings for above properties are missing. I think this can be added in this pr. Probably, we shouldn't be too verbose here and docstrings could be as:

>>> help(int.numerator)
Help on getset descriptor builtins.int.numerator:

numerator
    the numerator of a rational number in lowest terms

>>> help(int.denominator)
Help on getset descriptor builtins.int.denominator:

denominator
    the denominator of a rational number in lowest terms

>>>

Comment thread Doc/library/fractions.rst Outdated
@privet-kitty

Copy link
Copy Markdown
Author

@skirpichev Thanks for your review.

  • Fix rst according to your suggestion
  • Add docstrings to numerator and denominator of Fraction

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be more close to int docstrings.

CC @picnixz

Comment thread Lib/fractions.py Outdated
Comment thread Lib/fractions.py Outdated
privet-kitty and others added 2 commits July 31, 2024 21:57
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use a more imperative style like this. And yes we should match the docstring formulation of int, though I think we can add "(positive)" since for ints, the denominator is always "1".

Comment thread Lib/fractions.py Outdated
Comment thread Doc/library/fractions.rst Outdated

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, you could also add the docstring at the level of numbers.Rational.denominator rather than at the level of fractions.Fraction.denominator. Because the positivity of the denominator is for any subclass of Rational AFAIK (Fraction is a subclass of Rational)

@skirpichev

Copy link
Copy Markdown
Member

add the docstring at the level of numbers.Rational.denominator rather than at the level of fractions.Fraction.denominator. Because the positivity of the denominator is for any subclass of Rational

Good point. numbers.Rational assumes a specific canonical form for numerator/denominator (not just being positive).

privet-kitty and others added 3 commits August 1, 2024 23:06
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@privet-kitty

Copy link
Copy Markdown
Author

@picnixz @skirpichev Thanks. I reflected the suggestions and added docstrings to numerator and denominator of Rational

Comment thread Lib/fractions.py Outdated
Comment thread Lib/fractions.py Outdated
privet-kitty and others added 2 commits August 2, 2024 11:58
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
@privet-kitty

Copy link
Copy Markdown
Author

@skirpichev thanks, reflected

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose "expressed in its lowest terms" rather than "in lowest terms" for clarity.

What do you think @skirpichev ?

Comment thread Doc/library/fractions.rst
.. attribute:: numerator

Numerator of the Fraction in lowest term.
Numerator of the Fraction in lowest terms.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Numerator of the Fraction in lowest terms.
Numerator of the Fraction, expressed in its lowest terms.

Comment thread Doc/library/fractions.rst

Denominator of the Fraction in lowest term.

Positive denominator of the Fraction in lowest terms.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Positive denominator of the Fraction in lowest terms.
Positive denominator of the Fraction, expressed in its lowest terms.

Comment thread Lib/numbers.py
@property
@abstractmethod
def numerator(self):
"""The numerator of a rational number in lowest terms."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""The numerator of a rational number in lowest terms."""
"""The numerator of a rational number, expressed in its lowest terms."""

Comment thread Lib/numbers.py
@property
@abstractmethod
def denominator(self):
"""The (positive) denominator of a rational number in lowest terms."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""The (positive) denominator of a rational number in lowest terms."""
"""The (positive) denominator of a rational number, expressed in its lowest terms."""

@skirpichev

Copy link
Copy Markdown
Member

I propose "expressed in its lowest terms" rather than "in lowest terms" for clarity.

I think current wording is fine.

@python-cla-bot

python-cla-bot Bot commented Apr 18, 2025

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Comment thread Doc/library/fractions.rst
.. attribute:: numerator

Numerator of the Fraction in lowest term.
Numerator of the Fraction in lowest terms.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, we say that "The Fraction class inherits from the abstract base class numbers.Rational, and implements all of the methods and operations from that class."

So, we could move these numerator/denominator descriptions to the Rational class.

CC @AA-Turner

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be worse; it requires people to look in two places to find out what happens with Fraction. Happy to improve in both places, but we shouldn't remove from here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pr continued in #136800. I hope, I'll address review quickly;-)

but we shouldn't remove from here.

I'm not sure if it worth verbosity. I don't see e.g. where described real/imag properties for builtin types, except for the numbers module.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skirpichev should this PR (#122464) be closed?

A

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. I tried to attribute this work in a follow-up pr.

@AA-Turner

AA-Turner commented Jul 21, 2025

Copy link
Copy Markdown
Member

Closing: see #136800.

A

@AA-Turner AA-Turner closed this Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

6 participants